package jgcp.worker.process;

import java.util.Enumeration;
import java.util.Hashtable;

import jgcp.common.Task;
import jgcp.common.TaskStatus;
/**
 * 
 * @Date 31/05/2009
 * @author Peng Zhang(278819) Jie Zhao (288654)
 * @version 1.0
 */
public class TaskList {
	private TaskList() {
	}

	private static TaskList instance = new TaskList();

	/**
	 * @return the instance
	 */
	public static TaskList getInstance() {
		return instance;
	}

	private Hashtable<Task, Executer> store = new Hashtable<Task, Executer>();

	public void store(Task t, Executer exe) {
		store.put(t, exe);
	}

	public void cancel(int taskId) {
		Enumeration<Task> keys = store.keys();
		while (keys.hasMoreElements()) {
			Task t = keys.nextElement();
			if (t.getTaskid() == taskId) {
				store.get(t).cancel();
			}
		}
	}

	public TaskStatus getStatus(int taskId) {
		Enumeration<Task> keys = store.keys();
		while (keys.hasMoreElements()) {
			Task t = keys.nextElement();
			if (t.getTaskid() == taskId) {
				return t.getStatus();
			}
		}
		return TaskStatus.UNKNOWN;
	}
}
